﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace INF7GEN
{
    [Serializable()]
    public class UserCommand : ISerializable
    {   //EBNF form:
        //if player's command (logic) (logic test string), (action) the (arguments) [with (replacement string)].
        public static String[] Logic = {
                                     "matches",
                                     "includes",
                                     "does not match",
                                     "does not include"
                                 };
        public static String[] Action = {
                                      "replace",
                                      "cut"
                                  };
        public static String[] Arguments = {
                                         "player's command",
                                         "matched text"
                                     };
        private int chosenLogic = 0;
        private int chosenAction = 0;
        private int chosenArgument = 0;

        private String logicTestString = "";//if players command (matches/includes) [LogicTestString]
        private String replacementString = "";//used to replace argument

        private bool isStandardCommand = true;//if true then only logic/action/argument aspects are used

        private int id = 0;//usercommandID


        public UserCommand()
        {
        }
        //--------------------------------------------------------------------
        //Serialization-------------------------------------------------------
        public UserCommand(SerializationInfo info, StreamingContext ctxt)
        {
            this.IsStandardCommand = (bool)info.GetValue("COMMANDIsStandardCommand", typeof(bool));
            this.ChosenAction = (int)info.GetValue("COMMANDChosenAction", typeof(int));
            this.ChosenArgument = (int)info.GetValue("COMMANDChosenArgument", typeof(int));
            this.ChosenLogic = (int)info.GetValue("COMMANDChosenLogic", typeof(int));
            this.LogicTestString = (String)info.GetValue("COMMANDLogicTestString", typeof(String));
            this.ReplacementString = (String)info.GetValue("COMMANDReplacementString", typeof(String));
            this.ID = (int)info.GetValue("COMMANDID", typeof(int));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("COMMANDIsStandardCommand", this.IsStandardCommand);
            info.AddValue("COMMANDChosenAction", this.ChosenAction);
            info.AddValue("COMMANDChosenArgument", this.ChosenArgument);
            info.AddValue("COMMANDChosenLogic", this.ChosenLogic);
            info.AddValue("COMMANDLogicTestString", this.LogicTestString);
            info.AddValue("COMMANDReplacementString", this.ReplacementString);
            info.AddValue("COMMANDID", this.ID);
        }
        //-------------------------------------------------------------------

        public override string ToString()
        {
            string s = "" + this.id;
            return "id: " + s;
        }



        /// <summary>
        /// UserCommand boolean meaning is standard command type
        /// </summary>
        public bool IsStandardCommand
        {
            get { return this.isStandardCommand; }
            set { this.isStandardCommand = value; }
        }

        /// <summary>
        /// User Command int representing the chosen logic type(matches,includes,does not match...)
        /// </summary>
        public int ChosenLogic
        {
            get { return this.chosenLogic; }
            set { this.chosenLogic = value; }
        }

        /// <summary>
        /// User Command int id
        /// </summary>
        public int ID
        {
            get { return this.id; }
            set { this.id = value; }
        }

        /// <summary>
        /// User Command int representing the chosen argument type(players command, matched text)
        /// </summary>
        public int ChosenArgument
        {
            get { return this.chosenArgument; }
            set { this.chosenArgument = value; }
        }

        /// <summary>
        /// User Command int representing the chosen action type (replace, cut)
        /// </summary>
        public int ChosenAction
        {
            get { return this.chosenAction; }
            set { this.chosenAction = value; }
        }

        /// <summary>
        /// User Command String used to test players command against
        /// </summary>
        public String LogicTestString
        {
            get { return this.logicTestString; }
            set { this.logicTestString = value; }
        }

        /// <summary>
        /// User Command String used to test players command against
        /// </summary>
        public String ReplacementString
        {
            get { return this.replacementString; }
            set { this.replacementString = value; }
        }


    }
}
